package com.rybbaby.tss.front.tssPackage.dao.imp;

import com.rybbaby.tss.core.web.dao.imp.GenericDao;
import com.rybbaby.tss.front.tssPackage.dao.ITssPackageDao;
import com.rybbaby.tss.front.tssPackage.entity.TssPackage;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * @description 课时包表数据库操作实现
 * 
 * @author 雷春琼
 * 
 * @createDate 2017-08-10 上午12:08:51
 */
@Repository
public class TssPackageDaoImp extends GenericDao<TssPackage> implements ITssPackageDao {

    /**
     * 根据状态来修改员工信息
     *
     * @param targetDateId
     * @param isBlockUp
     * @return
     */
    @Override
    public Integer updatePackageByIsBlockUp(String targetDateId, Boolean isBlockUp) {
        return this.executeSql("update tss_package set updateTime=Now(),isBlockUp=? where id=?",new Object[]{isBlockUp,targetDateId});

    }


    /**
     * 根据课时包名称查询Id
     * */
    @Override
    public TssPackage findPackageByPackageName(String packageName) {
        String sql = "select * from tss_package where name in('"+packageName+"')";
        try {
            List<TssPackage> listBySql = findListBySql(sql, TssPackage.class, null);
            if (listBySql.isEmpty()){
                return null;
            } else{
                return listBySql.get(0);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }


    /**
     * 根据课时包id查询课时包总价
     * 杨然
     * */
    @Override
    public Double findSumPriceByPackageId(String packageId) {
        String sql = "select * from tss_package where id in('"+packageId+"')";
        try {
            List<TssPackage> listBySql = findListBySql(sql, TssPackage.class, null);
            if (listBySql.isEmpty()){
                return null;
            } else{
                return listBySql.get(0).getSumPrice();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}
